//
//  UIBarButtonItem+Button.swift
//  weibo007
//
//  Created by 陈宗毅 on 15/12/20.
//  Copyright © 2015年 czy. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    ///设置导航栏
    convenience init(imageName:String) {
        let button = UIButton()
        let hlImageName = imageName + "_highlighted"
        button.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: hlImageName), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        self.init(customView: button)
    }
    
    
    class func createBarButtonItem(imageName:String) -> UIBarButtonItem {
        
        let button = UIButton()
        let hlImageName = imageName + "_highlighted"
        button.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: hlImageName), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        return UIBarButtonItem(customView: button)
    }
}